package bankteam.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import bankteam.modelo.Cliente;

public class validacion {

	
	public static int validaGeneral(String nombTabla, String campo,String id)throws Exception {
	
		String query = "SELECT "+ campo + " from " +nombTabla+" where " + campo + "=?";
		
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		int valor =0;
		try {
			con  = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setString(1,id);
			rs = stmt.executeQuery();
			while (rs.next()) {
				valor = 1;
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			//throw new DAOExcepcion(e.getMessage());
		} finally {
			rs.close();
		}
		return valor;

	}	
	
	public static int validaGeneral(String nombTabla, String campo,int id)throws Exception {
		
		String query = "SELECT "+ campo + " from " +nombTabla+" where " + campo + "=?";
		
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		int valor =0;
		try {
			con  = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setInt(1,id);
			rs = stmt.executeQuery();
			while (rs.next()) {
				valor = 1;
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			//throw new DAOExcepcion(e.getMessage());
		} finally {
			rs.close();
		}
		return valor;

	}
}
